#!usr/bin/env python
# -*- coding:utf-8 -*-
# user nanme: Mr.zhang
# data time : 2022/9/16   6:32 下午
# project   : android.py
# IDE       : PyCharm
# email     :17600960626@163.com


import os
from lib.loggers import log
import uiautomator2 as u2



def device_android(d_id = 1) -> u2.Device:
    # log.info(d_id)
    if isinstance(d_id, int):
        return u2.connect()
    else:
        return u2.connect(d_id)


def devices():
    #获取设备列表
    a = os.popen('adb devices').readlines()
    if len(a) >= 2:
        dl = [i.split('\t')[0] for i in a if '\t' in i]
    else:
        dl = 'adb 异常，未获取到设备'
    return dl
